package com.example.springbootmqdemo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//可靠消费 后死信队列 config
public class DeadRabbitMqConfiguration {

    //1.声明一个交换机
    @Bean
    public DirectExchange deadDirectExchange() {
        return new DirectExchange("dead_direct_exchange", true, false);
    }


    //2. Queue
    @Bean
    public Queue deadQueue() {
        return new Queue("dead.direct.queue", true);
    }

    //3 绑定  将队列和交换机绑定
    @Bean
    //3.1  将队列dead.direct.queue 绑定到 名为 “dead_direct_exchange”的direct类型的交换机上 相对于fanout类型 多一个routKey = ”dead“参数
    public Binding deadBinding() {
        return BindingBuilder.bind(deadQueue()).to(deadDirectExchange()).with("dead");
    }

}
